package com.example.studentmanagement;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.studentmanagement.dao.StudentDao;
import com.example.studentmanagement.entity.Student;
import com.example.studentmanagement.util.DBUtil;
import com.example.studentmanagement.view.Top_Bar;

public class StudentInformationActivity extends AppCompatActivity {
    private StudentDao studentdao ;
    private Top_Bar top_bar ;
    private TextView s_name ;
    private TextView s_idD ;
    private TextView s_sex ;
    private TextView s_pro ;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_studentinformation);


        DBUtil dbUtil = new DBUtil(StudentInformationActivity.this);
        SQLiteDatabase db = dbUtil.getWritableDatabase();
        DBUtil.db=db;


        top_bar = findViewById(R.id.studentDetails);
        s_name = findViewById(R.id.sName) ;
        s_idD = findViewById(R.id.sId) ;
        s_sex = findViewById(R.id.sSex) ;
        s_pro = findViewById(R.id.sPro) ;
        studentdao = new StudentDao();


        top_bar.setTitleText("同学信息");
        top_bar.setRightBtnNoVisible(true);
        top_bar.setLeftBtnIsVisible(true);
        top_bar.setLeftBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        Intent intent = getIntent() ;
        String s_id = intent.getStringExtra("s_id") ;
        Log.d("111222333", "--------------"+s_id);
        Student student = studentdao.getStudentById(s_id);
        if (student != null){
            s_name.setText("姓名：" + student.getName());
            s_idD.setText("学号：" + s_id);
            s_sex.setText("性别：" + student.getSex());
            s_pro.setText("班级：" + student.getPro());
        }else {
            Toast.makeText(this, "未找到学生信息", Toast.LENGTH_SHORT).show();
        }

    }
}